package com.czz.portal.controller;

import com.czz.common.exception.ResultCodeEnum;
import com.czz.common.vo.R;
import com.czz.portal.entity.Teacher;
import com.czz.portal.service.TeacherService;
import com.czz.portal.vo.TeacherVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName: TeacherController
 * @Author Czz
 * @Date 2020/2/6
 * @Time 17:41
 **/
@RestController
@RequestMapping(value = "/teacher")
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    /**
    * @Description 获取首页讲师列表
    * @Param []
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/6
    * @Time 20:04
    **/
    @GetMapping(value = "")
    public R getTeacherList(){
        List<TeacherVo> teacherList = teacherService.getTeacherList();
        return R.ok().data("items",teacherList);
    }

    /**
    * @Description 根据课程id查询所属讲师信息
    * @Param [id]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/6
    * @Time 20:12
    **/
    @GetMapping(value = "/course/{id}")
    public R getTeacherByCourseId(@PathVariable String id){
        if (StringUtils.isEmpty(id)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        TeacherVo teacherVo = teacherService.getTeacherByCourseId(id);
        return R.ok().data("item",teacherVo);
    }

}
